<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:t="http://myfaces.apache.org/tomahawk" 
	template="/WEB-INF/layouts/admin-standard.xhtml">
	
	<ui:define name="content">
		<h:form enctype="multipart/form-data">
		  	<h:panelGrid columns="1">
		    	<t:inputFileUpload value="#{fileUploadController.uploadedFile}" storage="default" />
		  	</h:panelGrid>
		  	<h:commandButton value="Upload File" action="upload" />
			<h:commandButton value="Cancel" action="cancel" ajax="false"/>
		</h:form>
		<p:layout style="width:auto;height:800px;">
			<p:layoutUnit position="left" scrollable="true" collapsible="true" width="250">
				<h:form id="leftPanel">
					<p:treeTable value="#{productTreeBean.root}" var="product" style="width: 100%" >
						<p:column style="width:150px;">
							<f:facet name="header">
								Name
							</f:facet>
							<h:outputText value="#{product.name}" style="width:100px" rendered="#{product.class == 'class org.veetouch.model.VtMainproduct'}"/>
							<p:commandLink update=":centerPanel" action="viewTestCaseList" style="width:100px;" rendered="#{product.class == 'class org.veetouch.model.VtSubproduct'}">
								<h:outputText value="#{product.name}" style="width:100px" />
								<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedSubProduct}" />
							</p:commandLink>
						</p:column>
						<p:column style="width:100px;">
							<f:facet name="header">
								<div align="center">
									<p:commandLink title="Add Main-Product" styleClass="ui-icon ui-icon-plusthick" oncomplete="addMainProduct.show()"/>
								</div>
							</f:facet>
							<div align="center" >
								<h:panelGrid columns="3" styleClass="panel-grid-toolbox" rendered="#{product.class == 'class org.veetouch.model.VtMainproduct'}">
									<p:commandLink update=":editMainProductForm" oncomplete="editMainProduct.show()" title="Edit Main product" styleClass="ui-icon ui-icon-pencil" >
										<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedMainProduct}" />
									</p:commandLink>
									<p:commandLink update=":form:leftPanel" oncomplete="removeMainProduct.show()" title="Delete Main product" styleClass="ui-icon ui-icon-trash" >
										<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedMainProduct}" />
									</p:commandLink>
									<p:commandLink title="Add Sub Product" styleClass="ui-icon ui-icon-plusthick" onclick="addSubProduct_Des.init()" oncomplete="addSubProduct.show()">
										<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedMainProduct}" />
									</p:commandLink>
								</h:panelGrid>
								<h:panelGrid columns="3" styleClass="panel-grid-toolbox" rendered="#{product.class == 'class org.veetouch.model.VtSubproduct'}">
									<p:commandLink update=":editSubProductForm" onclick="editSubProduct_Des.init()" oncomplete="editSubProduct.show()" title="Edit Sub product" styleClass="ui-icon ui-icon-pencil" >
										<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedSubProduct}" />
									</p:commandLink>
									<p:commandLink update=":form:leftPanel" oncomplete="removeSubProduct.show()" title="Delete Sub product" styleClass="ui-icon ui-icon-trash" >
										<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedSubProduct}" />
									</p:commandLink>
									<p:commandLink title="Add Product" styleClass="ui-icon ui-icon-plusthick" onclick="addProduct_Des.init()" oncomplete="addProduct.show()">
										<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedSubProduct}" />
									</p:commandLink>
								</h:panelGrid>
							</div>
						</p:column>
					</p:treeTable>
				</h:form>
			</p:layoutUnit>
			<p:layoutUnit position="center" scrollable="true" collapsible="true" >
				<h:form id="centerPanel">
					<p:dataTable var="product" value="#{products}"
		                 paginator="true" rows="15"
		                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">
				        <f:facet name="header">
				            List of Product
				        </f:facet>
				        <p:column>  
				            <f:facet name="header">  
				                <h:outputText value="Name" />  
				            </f:facet>  
				            <h:outputText value="#{product.name}" />
				         </p:column>
				         <p:column>  
				            <f:facet name="header">  
				                <h:outputText value="Description" />  
				            </f:facet>
				            <h:outputText value="#{product.description}" escape="false"/>
				         </p:column>
				         <p:column  style="width:80px;">
				            <div align="center" >
								<h:panelGrid id="panel" columns="2" styleClass="panel-grid-toolbox" columnClasses="panel-grid-toolbox-column" style="width:auto;">
									<p:commandLink update=":editProductForm" onclick="editProduct_Des.init()" oncomplete="editProduct.show()" title="Edit Product" styleClass="ui-icon ui-icon-pencil" >
										<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedProduct}" />
									</p:commandLink>
									<p:commandLink update=":form:centerPanel" oncomplete="removeProduct.show()" title="Delete Product" styleClass="ui-icon ui-icon-trash" >
										<f:setPropertyActionListener value="#{product}" target="#{vt_adminproductService.selectedProduct}" />
									</p:commandLink>
								</h:panelGrid>
							</div>
				         </p:column>
		        	</p:dataTable>
				</h:form>
			</p:layoutUnit>
		</p:layout>
		
		<!-- 
		****************************************
		Add Dialog
		****************************************  
		-->
		<p:dialog  widgetVar="addMainProduct" header="New Main Product" modal="true" hideEffect="explode">
			<h:form>
				<p:messages />
				<h:panelGrid columns="2">
					<h:outputLabel value="Main Product Name * " for="addMainProduct_Name"/>
					<h:inputText id="addMainProduct_Name" value="#{vt_adminproductService.productName}" required="true"/>
					<p:commandButton type="submit" value="save"   action="add-MainProduct" update="@form,:leftPanel" oncomplete="resultStatus(xhr, status, args,addMainProduct);"/>
					<p:commandButton type="reset"  value="cancel" onclick="addMainProduct.hide()" immediate="true" />
				</h:panelGrid>
			</h:form>
		</p:dialog>
		
		<p:dialog  widgetVar="addSubProduct" header="New Sub Product" modal="true" hideEffect="explode">
			<h:form>
				<p:messages />
				<h:panelGrid columns="2">
					<h:outputLabel value="Sub Product Name * " for="addSubProduct_Name"/>
					<h:inputText id="addSubProduct_Name" value="#{vt_adminproductService.productName}" required="true"/>
					<h:outputLabel value="Description " />
					<p:editor widgetVar="addSubProduct_Des" lazy="true" value="#{vt_adminproductService.productDes}" width="600" />
					<p:commandButton type="submit" value="save"   action="add-SubProduct" update="@form,:leftPanel" oncomplete="resultStatus(xhr, status, args,addSubProduct);"/>
					<p:commandButton type="reset"  value="cancel" onclick="addSubProduct.hide()" immediate="true" />
				</h:panelGrid>
			</h:form>
		</p:dialog>
		
		<p:dialog  widgetVar="addProduct" header="New Product" modal="true" hideEffect="explode">
			<h:form enctype="multipart/form-data">
				<p:messages />
				<h:panelGrid columns="2">
					<h:outputLabel value="Product Name * " for="addProduct_Name"/>
					<h:inputText id="addProduct_Name" value="#{vt_adminproductService.productName}" required="true"/>
					<h:outputLabel value="Description " />
					<p:editor widgetVar="addProduct_Des" lazy="true" value="#{vt_adminproductService.productDes}" width="600" />
					<h:outputLabel value="Logo image " />
					<h:panelGrid columns="2">
		    			<t:inputFileUpload value="#{fileUploadController.uploadedFile}" storage="default" />
		  			</h:panelGrid>
		  			<h:commandButton value="save"   action="add-Product" update="@form,:centerPanel" oncomplete="resultStatus(xhr, status, args,addProduct);"/>
		  			<h:commandButton value="cancel" onclick="addProduct.hide()" immediate="true" />
		  			<!-- 
		  			<p:commandButton type="submit" value="save"   action="add-Product" update="@form,:centerPanel" oncomplete="resultStatus(xhr, status, args,addProduct);"/>
					<p:commandButton type="reset"  value="cancel" onclick="addProduct.hide()" immediate="true" />
					 -->
				</h:panelGrid>
			</h:form>
		</p:dialog>
		
		<!-- 
		**************************************** 
		Edit Dialog
		**************************************** 
		-->
		<p:dialog widgetVar="editMainProduct" header="Edit Main Product" modal="true">
			<h:form id="editMainProductForm">
				<p:messages />
				<h:panelGrid columns="2">
					<h:outputLabel value="Main Product Name * " for="editModName"></h:outputLabel>
					<h:inputText id="editMainProduct_Name" value="#{vt_adminproductService.selectedMainProduct.name}" required="true" />
					<p:commandButton type="submit" value="save" action="edit-MainProduct" update="@form,:leftPanel" oncomplete="resultStatus(xhr, status, args,editMainProduct)" />
					<p:commandButton type="reset" value="cancel" onclick="editMainProduct.hide()" />
				</h:panelGrid>
			</h:form>
		</p:dialog>

		<p:dialog widgetVar="editSubProduct" header="Edit Sub Product" modal="true">
			<h:form id="editSubProductForm">
				<p:messages />
				<h:panelGrid columns="2">
					<h:outputLabel value="Sub Product Name * "/>
					<h:inputText value="#{vt_adminproductService.selectedSubProduct.name}" required="true"/>
					<h:outputLabel value="Description " />
					<p:editor widgetVar="editSubProduct_Des" value="#{vt_adminproductService.selectedSubProduct.description}" width="600" />
					<p:commandButton type="submit" value="save"   action="edit-SubProduct" update="@form,:leftPanel" oncomplete="resultStatus(xhr, status, args,editSubProduct);"/>
					<p:commandButton type="reset"  value="cancel" onclick="editSubProduct.hide()" immediate="true" />
				</h:panelGrid>
			</h:form>
		</p:dialog>
		
		<p:dialog widgetVar="editProduct" header="Edit Product" modal="true">
			<h:form id="editProductForm">
				<p:messages />
				<h:panelGrid columns="2">
					<h:outputLabel value="Product Name * "/>
					<h:inputText value="#{vt_adminproductService.selectedProduct.name}" required="true"/>
					<h:outputLabel value="Description " />
					<p:editor widgetVar="editProduct_Des" value="#{vt_adminproductService.selectedProduct.description}" width="600" />
					<p:commandButton type="submit" value="save"   action="edit-Product" update="@form,:centerPanel" oncomplete="resultStatus(xhr, status, args,editProduct);"/>
					<p:commandButton type="reset"  value="cancel" onclick="editProduct.hide()" immediate="true" />
				</h:panelGrid>
			</h:form>
		</p:dialog>
		
		<!-- 
		**************************************** 
		Delete Dialog
		****************************************  
		-->		
		<p:confirmDialog widgetVar="removeMainProduct" message="Are you sure?" width="200"  hideEffect="explode"  
                    header="Confirm" severity="alert" >
            <h:form>
        		<p:commandButton value="Yes sure" action="remove-MainProduct" update="@form,:leftPanel" oncomplete="removeMainProduct.hide()"/>  
        		<p:commandButton value="Not yet"  onclick="removeMainProduct.hide()" type="button" />  
    		</h:form>
    	</p:confirmDialog> 
    	
    	<p:confirmDialog widgetVar="removeSubProduct" message="Are you sure?" width="200"  hideEffect="explode" header="Confirm" severity="alert" >
            <h:form>
        		<p:commandButton value="Yes sure" action="remove-SubProduct" update="@form,:leftPanel" oncomplete="removeSubProduct.hide()"/>  
        		<p:commandButton value="Not yet"  onclick="removeSubProduct.hide()" type="button" />
    		</h:form>
    	</p:confirmDialog>
    	
    	<p:confirmDialog widgetVar="removeProduct" message="Are you sure?" width="200"  hideEffect="explode" header="Confirm" severity="alert" >
            <h:form>
        		<p:commandButton value="Yes sure" action="remove-Product" update="@form,:centerPanel" oncomplete="removeProduct.hide()"/>  
        		<p:commandButton value="Not yet"  onclick="removeProduct.hide()" type="button" />
    		</h:form>
    	</p:confirmDialog>
		
		<script>
			function resultStatus(xhr, status, args,widgetVar)
			{
				if(!args.saved)
				{
					saveFailedDialog.show();
				}
				else
				{
					widgetVar.hide();
				}
			}
		</script>
	</ui:define>
	
</ui:composition>